<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
 * Description of category_model
 *
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_messages_model extends CI_Model {

	//put your code here


	function __construct() {
		parent::__construct();
		log_message('debug', 'Init Model Initialized');
	}
	
	//------------Get All News()----------
	function get_all_messages($num=NULL, $offset=NULL) {
		//$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from message " . /*$subcond .*/ $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	function search($search=null){
		$sql = "Select * from message where description like '%$search%' order by id desc";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $query->result();
		}else{
			return false;
		}
	
	
	}
	function change_status($id, $status) {
		if ($status == 1) {
			$sql = "update message set status=51 where id=$id";
		}
		if ($status == 51) {
			$sql = "update message set status=1 where id=$id";
		}
		$this->db->query($sql);
	}
	
	function get_message($id=NULL)
	{
		$sql="select * from message where id=$id";
		$query=$this->db->query($sql);
		$row=$query->row();
		return $row;
	}
	
	function delete($id=NULL)
	{
		$sql="delete from message where id=$id";
		$this->db->query($sql);
	}
	
}